package com.stroke.core.helpers;

import com.stroke.core.InputHandler;
import com.stroke.entity.Entity;

import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.util.List;

/**
 * Author: Igor Bubelov
 * Date: 3/7/11 11:49 PM
 */
public class UpdateHelper {
    public static void processInput(List<Entity> entities, InputHandler handler) {
        for (Entity entity : entities) {
            for (KeyEvent event : handler.getKeyTypedEvents()) {
                entity.keyTyped(event);
            }
            for (KeyEvent event : handler.getKeyPressedEvents()) {
                entity.keyPressed(event);
            }
            for (KeyEvent event : handler.getKeyReleasedEvents()) {
                entity.keyReleased(event);
            }
            for (MouseEvent event : handler.getMouseClickedEvents()) {
                entity.mouseClicked(event);
            }
            for (MouseEvent event : handler.getMousePressedEvents()) {
                entity.mousePressed(event);
            }
            for (MouseEvent event : handler.getMouseReleasedEvents()) {
                entity.mouseReleased(event);
            }
            for (MouseEvent event : handler.getMouseEnteredEvents()) {
                entity.mouseEntered(event);
            }
            for (MouseEvent event : handler.getMouseExitedEvents()) {
                entity.mouseExited(event);
            }
            for (MouseEvent event : handler.getMouseDraggedEvents()) {
                entity.mouseReleased(event);
            }
            for (MouseEvent event : handler.getMouseMovedEvents()) {
                entity.mouseReleased(event);
            }
            for (MouseWheelEvent event : handler.getMouseWheelMovedEvents()) {
                entity.mouseWheelMoved(event);
            }
        }

        handler.clearEvents();
    }
}
